package com.kx.smsplatform.deadletter.config;

import com.rabbitmq.client.BuiltinExchangeType;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author Sun
 * @Date 2021/7/8 21:49
 */
public class DelayedConfig {
    public static final String DELAYED_EXCHANGE = "delayed-exchange";

    public static final String DELAYED_QUEUE = "delayed-queue";



    @Bean
    public Exchange delayedExchange(){
        Map<String, Object> args = new HashMap<>();
        args.put("x-delayed-type", BuiltinExchangeType.FANOUT.getType());//fanout
        CustomExchange exchange = new CustomExchange(DELAYED_EXCHANGE,"x-delayed-message",true,false,args);
        return exchange;
    }

    @Bean
    public Queue delayedQueue(){
        return QueueBuilder.durable(DELAYED_QUEUE).build();
    }

    @Bean
    public Binding delayedBinding(Queue delayedQueue,Exchange delayedExchange){
        return BindingBuilder.bind(delayedQueue).to(delayedExchange).with("").noargs();
    }
}
